from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response
from netbook.utils import *

def publiclist(request):
    num = api.getAllPublicNoteNumber(session='')
    notelist = api.getAllPublicNoteList(session='',start=uint64(0),count=uint32(int(num)),field=uint32(1023))
    return render_to_response('note_list.html',{'notelist':notelist},context_instance=RequestContext(request))

def publicNoteList(request):
    num = api.getAllPublicNoteNumber(session='')
    notelist = api.getAllPublicNoteList(session='',start=uint64(0),count=uint32(int(num)),field=uint32(1023))
    return render_to_response('public_note_list.html',{'notelist':notelist},context_instance=RequestContext(request))

def note(request, note_id):
    uuid = request.session["uuid"]
    try:
	note = api.getNoteById(session=uuid,note_id=uint64(int(note_id)),field=uint32(1023))
	note.title = latin1(note.title) 
	note.content = latin1(note.content) 
    except SOAPpy.faultType as ft:
	note = False
    return render_to_response('note.html',{'note':note},context_instance=RequestContext(request))

def myNoteList(request):
    uuid = request.session["uuid"]
    num = api.getMyNoteNumber(session=uuid)
    notelist = api.getMyNoteList(session=uuid,start=uint64(0),count=uint32(int(num)),field=uint32(1023))
    return render_to_response('my_note_list.html',{'notelist':notelist},context_instance=RequestContext(request))

def meta(request):
    metas = request.META.items()
    metas.sort()
    return render_to_response('meta.html',{'values':metas})

